package com.scu.bank.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scu.bank.model.dao.MessageDao;
import com.scu.bank.model.example.MessageExample;
import com.scu.bank.model.pojo.Message;
import com.scu.bank.model.base.BaseServiceImpl;
import com.scu.bank.service.MessageService;
import com.scu.bank.util.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by pmeng on 2021/01/05.
 */
@Service
@Transactional
public class MessageServiceImpl extends BaseServiceImpl<Message,MessageDao> implements MessageService {
    @Autowired
    private MessageDao tSysMessageDao;

    @Override
    public MessageDao getDao() {
        return tSysMessageDao;
    }

    @Override
    public PageInfo<Message> list(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        MessageExample example = new MessageExample();
        example.createCriteria().andIsDelEqualTo(false);
        PageInfo pageInfo = new PageInfo(tSysMessageDao.selectByExample(example));
        return pageInfo;
    }

    @Override
    public void addMessage(Message message) {
        message.setType("0");
        message.setSender(WebUtil.getCurrentUserId());
        save(message);
    }
}
